<?php

/**
 * This is the model class for table "tbl_intropage".
 *
 * The followings are the available columns in table 'tbl_intropage':
 * @property string $id
 * @property string $id_course
 * @property string $tutor_name
 * @property string $tutor_address
 * @property string $tutor_phone
 * @property string $salary
 * @property string $reason
 * @property string $createDate
 * @property string $failDate
 */
class Intropage extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Intropage the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_intropage';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_course, tutor_name, tutor_address', 'required'),
			array('id_course, tutor_phone, salary', 'length', 'max'=>20),
			array('tutor_name', 'length', 'max'=>100),
			array('tutor_address', 'length', 'max'=>200),
			array('reason, createDate, failDate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, id_course, tutor_name, tutor_address, tutor_phone, salary, reason, createDate, failDate', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'course' => array(self::BELONGS_TO, 'Course', 'id_course'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'id_course' => 'Mã lớp',
			'tutor_name' => 'Giáo viên',
			'tutor_address' => 'Đ/c GV',
			'tutor_phone' => 'SĐT',
			'salary' => 'Lương',
			'reason' => 'Lý do',
			'createDate' => 'Ngày tạo',
			'failDate' => 'Ngày báo lỗi',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);

		$criteria->compare('id_course',$this->id_course,true);

		$criteria->compare('tutor_name',$this->tutor_name,true);

		$criteria->compare('createDate',$this->createDate,true);

		$criteria->compare('failDate',$this->failDate,true);

                $criteria->order = 'id DESC';

		return new CActiveDataProvider('Intropage', array(
			'criteria'=>$criteria,
                        'pagination'=>array(
                            'pageSize'=>10,
                        ),
		));
	}
}